<!-- 检测详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 32rpx;" slot="content">检测详情</block>
		</cu-custom>
		<view class="content" style="background-color: #fff;">
			<ul>
				<li>
					<text class="list-info">任务名称：</text>
					<text class="list-title">{{examineTaskInfo.taskName || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">检查人员：</text>
					<text class="list-title">{{examineTaskInfo.executorName || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">被检单位：</text>
					<text class="list-title">{{examineTaskInfo.enterpriseName || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">检查时间：</text>
					<text class="list-title">{{examineTaskInfo.addTime || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">检测企业：</text>
					<text class="list-title">{{examineTaskInfo.examineName || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">任务状态：</text>
					<text class="list-title">{{mainFormat(examineTaskInfo.examineStatus)}}</text>
				</li>
			</ul>
		</view>

		<view v-for="(item,index) in tree" :key="index">
			<view class="zj" @click="close(index)">
				<view>{{item.name}}：已完成 <text class="title_big state-green">{{item.doneNum}}</text> 个 / 需要完成 <text
						class="title_big">{{item.totalNum}}</text> 个</view>
				<uni-icons class="close" :type="iconStyles[index]" size="16"></uni-icons>
			</view>
			<view :style="pShows[index]? '' : 'display:none;'" class="detail">
				<view v-for="(c,cindex) in tree[index].children" :key="cindex" style="display: flex;flex-direction: row;justify-content: space-between;">
					<text>{{c.name + ' : 已完成' }}<text class="title_big state-green">{{c.doneNum}}</text>{{'项/需要完成'}}<text class="title_big">{{c.totalNum}}</text>{{'项'}}</text>
					<button v-if="examineTaskInfo.examineStatus==3 && !examineTaskInfo.isStop" style="width: 120rpx;padding: 0;" class="bg-system-orange shadow"
						@click="see_detail(c)">{{ examineTaskInfo.status ===1? '修改检测':'开始检测' }}</button>
				</view>
			</view>
		</view>


		<view v-if="examineTaskInfo.examineStatus==2 " class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @click="startExecute()">开始执行</button>
		</view>

		<view v-if="examineTaskInfo.examineStatus==3 && examineTaskInfo.isStop" class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @click="setStartExamine()">继续执行</button>
		</view>
		
		<view v-if="examineTaskInfo.examineStatus==3 && !examineTaskInfo.isStop " class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @click="setStartExamine()">暂停执行</button>
		</view>

		<view v-if="examineTaskInfo.examineStatus==3" class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn bg" @click="completeTask()">结束本次检测任务</button>
		</view>
		<message />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				examineTaskInfo: {},
				pShows:[],
				pShow: false,
				iconStyle: 'top',
				iconStyles:[],
				otype: 0,
				ucId: '',
				tree: [],
				mainOptions: []
			}
		},
		onLoad(option) {
			this.ucId = option.ucId
			this.initView()
		},
		methods: {
			initView() {
				let that = this
				that.getDicts("examine_status", that).then(response => {
					that.mainOptions = response.data.data;
				});
				that.xq()
			},
			mainFormat(data) {
				return this.selectDictLabel(this.mainOptions, data);
			},
			see_detail(value) {
				if(value.bind==null){
					value.bind = false
				}
				uni.navigateTo({
					url: '/jcqy/jcxm/jcxm?taskId=' + value.taskId + '&code=' + value.code + '&status=' +
						value.status + '&totalNum=' + value.totalNum + '&bind=' + true + '&devType=' + value.devType
				})
			},
			close(index) {
				console.info("index:" +index+" "+this.pShows[index])
				this.pShows[index] = !this.pShows[index];
				this.pShow = !this.pShow;
				this.iconStyle = this.pShow ? 'bottom' : 'top'
				this.iconStyles[index] = this.pShows[index] ? 'bottom' : 'top'
			},
			xq() {
				// 封装参数
				let params = {
					"ucId": this.ucId
				}
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/getInExamineProjectTree',
					data: params
				}).then(function(res) {
					that.examineTaskInfo = res.data.data.task
					if(!that.examineTaskInfo.examineName) {
						that.examineTaskInfo.examineName == ''
					}
					that.tree = res.data.data.tree
					for(let i =0;i<that.tree.length;i++){
						that.pShows[i] = false;
						that.iconStyles[i]='top';
					}
					 
				}).catch(function(e) {

				})
			},
			startExecute() {
				let that = this
				let params = {
					"enterpriseId": that.examineTaskInfo.enterpriseId,
					"ucId": that.ucId
				}
				// 生成报警信息
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/startExecute',
					method: "GET",
					data: params
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "开始执行成功",
						type: 'success'
					})
					that.initView()
				}).catch(function(e) {})
			},
			setStartExamine() {
				let that = this
				let params = {
					"enterpriseId": that.examineTaskInfo.enterpriseId,
					"ucId": that.ucId,
					"isStop": that.examineTaskInfo.isStop
				}
				let msg = ""
				if(that.examineTaskInfo.isStop){
					msg = "继续执行成功"
				}else{
					msg = "暂停执行成功"
				}
				// 生成报警信息
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/setStartExamine',
					method: "GET",
					data: params
				}).then(function(res) {
					that.$refs.uToast.show({
						message: msg,
						type: 'success'
					})
					that.initView()
				}).catch(function(e) {})
			},
			completeTask() {
				let that = this
				let params = {
					"enterpriseId": that.examineTaskInfo.enterpriseId,
					"ucId": that.ucId
				}
				// 生成报警信息
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/completeTask',
					method: "GET",
					data: params
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "提交成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {
					that.$refs.uToast.show({
						message: e.data.msg,
						type: 'error'
					})
				})
			}
		}
	}
</script>

<style scoped>
	page {
		width: 100vw;
	}

	.content {
		margin-top: 24rpx;
		background-color: #FFFFFF;
	}

	ul li {
		list-style: none;
		margin: 0;
		padding: 0;
		margin-left: 24rpx;
		position: relative;
	}

	li text {
		font-size: 24rpx;
		/* color: #777777; */
		line-height: 94rpx;
	}

	li::after {
		content: '';
		position: absolute;
		left: 2rpx;
		bottom: 0;
		right: 2rpx;
		height: 1px;
		background-color: #dcdcdc;
	}

	.zj {
		display: flex;
		justify-content: space-between;
		margin-top: 24rpx;
		padding-left: 24rpx;
		background: #FFFFFF;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 24rpx;
		color: #333333;
	}

	.detail {
		display: flex;
		flex-direction: column;

	}

	.detail text {
		line-height: 105rpx;
		font-size: 21rpx;
	}

	.detail button {
		float: right;
		width: 140rpx;
		height: 50rpx;
		background: #FABD50;
		box-shadow: 0 4px 14px 0 rgba(250, 189, 80, 0.50);
		border-radius: 6px;
		border-radius: 6px;

		font-size: 21rpx;
		color: #FFFFFF;
		margin-bottom: 20rpx;
		position: absolute;
		right: 0;
		bottom: 10rpx;

	}

	.detail view {
		margin: 10rpx 40rpx;
		border-bottom: 1px solid #CCCCCC;
		position: relative;
	}

	.title_big {
		color: #FABD50;
		font-size: 32rpx;
		font-weight: 600;
		display: inline-block;
		padding: 0 12rpx;
	}
	.bg {
		color: #FABD50 !important;
		background: #fff !important;
	}

	.close {
		width: 80rpx;
	}

	.padding{
		padding: 0 30px;
	}
	.my-btn {
		height: 94rpx;
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
		border-radius: 24px;
		font-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
	}
</style>
